package com.gimi.cloud.jimi.manage.controller.prod;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.product.LogisticsCompanyDTO;
import com.gimi.cloud.jimi.entity.product.LogisticsCompanyEntity;
import com.gimi.cloud.jimi.manage.service.prod.LogisticsCompanyService;
import com.github.pagehelper.PageInfo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 物流公司信息
 * @author chendi
 * @date 2018年1月18日
 */
@RestController
@RequestMapping(value = "LogisticsCompany")
public class LogisticsCompanyController {
	
    private static Logger logger = LoggerFactory.getLogger(LogisticsCompanyController.class);

    @Autowired
    private LogisticsCompanyService logisticsCompanyService;

    /**
     * 列表分页
     */
    @RequestMapping(value = "/pageList")
    public void LogisticsCompanypageList(@RequestBody LogisticsCompanyDTO dto, HttpServletRequest request, HttpServletResponse response) {
        Response resp = new Response();
        PageInfo<LogisticsCompanyEntity> list = logisticsCompanyService.logisticsCompanyPageList(dto);
        resp.setRes_data(list);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }


    /**
     * 添加/更新
     */
    @RequestMapping(value = "/add")
    public void LogisticsCompanyAdd(@RequestBody LogisticsCompanyDTO dto, HttpServletRequest request, HttpServletResponse response) {
        Response resp = new Response();
        logisticsCompanyService.updateLogisticsCompany(dto);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
    
    /** 删除 */
    @RequestMapping(value = "/delete")
    public void deleteLogisticsCompany(@RequestBody LogisticsCompanyDTO dto, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	logisticsCompanyService.deleteLogisticsCompany(dto);
    	resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
    	Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    /** 获得单个实体信息 */
    @RequestMapping(value = "/getSingle")
    public void getSingleLogisticsCompany(@RequestBody LogisticsCompanyDTO dto, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	LogisticsCompanyDTO companyDTO = logisticsCompanyService.getSingleLogisticsCompany(dto);
    	resp.setRes_data(companyDTO);
    	resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
    	Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
}
